package com.lzw.mall.admin.controller;


import com.lzw.mall.admin.entity.Menu;
import com.lzw.mall.common.entity.Category;
import com.lzw.mall.common.service.ICategoryService;
import com.lzw.mall.common.vo.LayuiTableVO;
import com.lzw.mall.common.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lizhenwei
 * @since 2023-03-18
 */
@Controller
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private ICategoryService categoryService;

    @GetMapping("/index")
    public String index() {
        return "category";
    }

    @GetMapping("/list")
    @ResponseBody
    public LayuiTableVO list(@RequestParam Integer page, @RequestParam Integer limit, String keyword){
        return categoryService.list(page, limit, keyword);
    }

    @ResponseBody
    @PostMapping("/avatar")
    public ResultVO avatar(MultipartFile file){
        return categoryService.avatar(file);
    }


    @ResponseBody
    @PostMapping("/save")
    public ResultVO save(Category c) {

        return categoryService.doSave(c);
    }

    @PostMapping("/del")
    @ResponseBody
    public void del(Integer id){
        categoryService.doDelete(id);
    }

    @GetMapping("/{id}")
    @ResponseBody
    public Category selectById(@PathVariable("id") Integer id){
        return categoryService.getById(id);
    }

    @GetMapping("/child")
    @ResponseBody
    public List<Category> child(Integer id){
        return categoryService.selectByParentId(id);
    }
}
